package com.dlc.shop.systemtest.data.maketing;

import cn.hutool.core.date.DateUtil;
import com.dlc.shop.bean.model.Product;
import com.dlc.shop.combo.multishop.model.Combo;
import com.dlc.shop.combo.multishop.model.ComboProd;
import com.dlc.shop.combo.multishop.model.ComboProdSku;
import com.dlc.shop.systemtest.api.amount.ProductApi;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lpj
 */
public class ComboData {

    /**
     * 获取套餐数据
     */
    public static Combo getCombo(Long mainProductId, List<Long> matchingProductIds) {
        Combo combo = new Combo();
        combo.setName("测试套餐接口");
        combo.setStartTime(DateUtil.parse("2023-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        combo.setEndTime(DateUtil.parse("2025-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        combo.setMainProd(getComboMainProd(mainProductId));
        combo.setMatchingProds(getMatchingComboProd(matchingProductIds));

        return combo;
    }

    /**
     * 获取套餐主商品数据
     */
    public static ComboProd getComboMainProd(Long mainProductId) {
        ComboProd comboProd = new ComboProd();
        Product product = ProductApi.getProductInfo(mainProductId);
        comboProd.setProdId(mainProductId);
        comboProd.setLeastNum(3);
        comboProd.setRequired(1);
        comboProd.setPic(product.getPic());
        comboProd.setPrice(product.getPrice());
        comboProd.setProdName(product.getProdName());

        List<ComboProdSku> comboProdSkus = new ArrayList<>();
        for (int i=0; i<product.getSkuList().size(); i++) {
            ComboProdSku comboProdSku = new ComboProdSku();
            comboProdSku.setSkuId(product.getSkuList().get(i).getSkuId());
            comboProdSku.setMatchingPrice(66.0);
            comboProdSku.setPrice(product.getSkuList().get(i).getPrice());
            comboProdSku.setStocks(product.getSkuList().get(i).getStocks());
            comboProdSku.setPic(product.getSkuList().get(i).getPic());
            comboProdSku.setSkuName(product.getSkuList().get(i).getSkuName());
            comboProdSku.setProperties(product.getSkuList().get(i).getProperties());
            comboProdSkus.add(comboProdSku);
        }
        comboProd.setSkuList(comboProdSkus);

        return comboProd;
    }

    /**
     * 获取套餐搭配商品数据
     */
    public static List<ComboProd> getMatchingComboProd(List<Long> matchingProductIds) {
        List<ComboProd> comboProds = new ArrayList<>();
        for (Long matchingProductId : matchingProductIds) {
            Product product = ProductApi.getProductInfo(matchingProductId);
            ComboProd comboProd = new ComboProd();
            comboProd.setProdId(product.getProdId());
            comboProd.setLeastNum(2);
            comboProd.setRequired(0);
            comboProd.setPic(product.getPic());
            comboProd.setPrice(product.getPrice());
            comboProd.setProdName(product.getProdName());

            List<ComboProdSku> comboProdSkus = new ArrayList<>();
            for (int i = 0; i < product.getSkuList().size(); i++) {
                ComboProdSku comboProdSku = new ComboProdSku();
                comboProdSku.setSkuId(product.getSkuList().get(i).getSkuId());
                comboProdSku.setMatchingPrice(66.0);
                comboProdSku.setPrice(product.getSkuList().get(i).getPrice());
                comboProdSku.setStocks(product.getSkuList().get(i).getStocks());
                comboProdSku.setPic(product.getSkuList().get(i).getPic());
                comboProdSku.setSkuName(product.getSkuList().get(i).getSkuName());
                comboProdSku.setProperties(product.getSkuList().get(i).getProperties());
                comboProdSkus.add(comboProdSku);
            }
            comboProd.setSkuList(comboProdSkus);
            comboProds.add(comboProd);
        }

        return comboProds;
    }


}
